package com.example.demo.controller.game;

import java.util.ArrayList;
import java.util.List;

public class GameCtrl {
    public static void main(String[] args) {
        // 初始化
        // 随机生成一个拥有4个检查点，3个飞机的地图
        MapCtrl mapCtrl = new MapCtrl(4,"hdl","du","du");
        for(int i=0;i<10;i++){
            String input,output;
            input = "5000 3000 100\n" +
                    "4000 2000 80\n" +
                    "4000 2000 60";//几个飞船就有几行输入，分别表示飞向的坐标和油门大小
            output = play(input,mapCtrl);//输出四个参数，分别表示飞船当前位置和目的地位置
            System.out.println("Input:\n"+input+"\nOutput:\n"+output);
        }
    }
    static String play(String input,MapCtrl mapCtrl){
        String inputs[] = input.replace('\n',' ').split(" ");
        if(inputs.length % 3 != 0){
            return "ERROR the length of inputs is "+inputs.length;
        }
        List<PlaneCmd> cmds = new ArrayList<>();
        for(int i=0;i<inputs.length;i+=3){
            cmds.add(new PlaneCmd(inputs[i],inputs[i+1],inputs[i+2]));
        }
        String output = "";
        for(Pot pot:mapCtrl.play(cmds)){
            Vec nextPoint = mapCtrl.checkPoints[(pot.visited.get(pot.visited.size()-1)+1)%mapCtrl.checkPoints.length];
            output += (String.format("%d %d %d %d\n",
                    Math.round(pot.pos.x),Math.round(pot.pos.y),
                    Math.round(nextPoint.x),Math.round(nextPoint.y)));
        }
        return output;
    }
}
